package com.alibaba.otter.node.etl.load.loader.mq.rabbit.strategy;

public class MqExceptionHandlerBuilder {

    private EndStrategyBuild endAction;

    public MqExceptionHandlerBuilder(EndStrategyBuild endBuilder) {
        this.endAction = endBuilder;
    }

    public MqExceptionHandlerBuilder then(RescueAction exceptionHandler) {
        endAction.addAction(exceptionHandler);
        return this;
    }

    public MqExceptionHandlerBuilder thenRetry(int retryTimes) {
        RetryInvoke retryInvoke = new RetryInvoke(retryTimes);
        endAction.addAction(retryInvoke);
        return this;
    }

    public MqExceptionHandlerBuilder thenRetry(RetryStrategy retryStrategy) {
        endAction.addAction(new RetryInvoke(retryStrategy));
        return this;
    }

    public MqExceptionHandlerBuilder thenSendToDLQ() {
        endAction.addAction(new SendToDLQ());
        return this;
    }

    public MqExceptionHandlerBuilder thenSendToDLQ(String exchange, String routingKey) {
        endAction.addAction(new SendToDLQ(exchange, routingKey));
        return this;
    }

    public MqExceptionHandlerBuilder thenSendToDLQ(String namespace, String exchange, String routingKey) {
        endAction.addAction(new SendToDLQ(namespace, exchange, routingKey));
        return this;
    }

    public MqExceptionHandlerBuilder thenNotify(String user) {
       // endAction.addAction(new NotifyUser(user));
        return this;
    }

//    public MqExceptionHandlerBuilder thenNotify(NotifyStrategy strategy) {
//        endAction.addAction(new NotifyUser(strategy));
//        return this;
//    }

    public EndStrategyBuild endWithAck() {
        endAction.setCurrentEndAction(new EndWithAck());
        return endAction;
    }

    public EndStrategyBuild endWith(EndAction endStrategy) {
        endAction.setCurrentEndAction(endStrategy);
        return endAction;
    }

    public EndStrategyBuild endWithNack() {
        endAction.setCurrentEndAction(new EndWithNack());
        return endAction;
    }

    public EndStrategyBuild endWithReject() {
        endAction.setCurrentEndAction(new EndWithReject());
        return endAction;
    }

    public EndStrategyBuild endWithBlock() {
        endAction.setCurrentEndAction(new BlockUntil());
        return endAction;
    }

    public EndStrategyBuild endWithlockUtils(UnblockCondition condition) {
        endAction.setCurrentEndAction(new BlockUntil(condition));
        return endAction;
    }
}
